
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>SQL执行与映射处理 - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>SQL执行与映射处理 - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">在MyBatis中，SQL执行的入口是什么？它最终会调用哪个核心组件来执行实际的数据库操作？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">MyBatis的SQL执行入口是通过`SqlSession`接口提供的，例如`selectOne`、`selectList`等方法。这些方法内部最终会调用`Executor`来执行SQL。</div>
          </div>
          <div class="card-source">来源: 1. SQL执行的入口与流程</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">核心组件</div>
          <div class="card-question">MyBatis中的`Executor`接口扮演什么角色？它主要负责哪些功能？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">核心组件</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`Executor`是MyBatis中负责执行SQL的核心接口，主要实现了SQL的执行、缓存管理、批量操作等功能。</div>
          </div>
          <div class="card-source">来源: 2. Executor的作用与执行流程</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">核心组件</div>
          <div class="card-question">什么是`MappedStatement`对象？它包含了哪些关于SQL语句的信息？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">核心组件</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`MappedStatement`是代表一个映射的SQL语句的关键对象，它包含了SQL语句的详细信息、参数类型、返回类型以及SQL命令类型（如SELECT, INSERT等）。</div>
          </div>
          <div class="card-source">来源: 3. MappedStatement的作用与获取</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">核心组件</div>
          <div class="card-question">`BoundSql`对象在MyBatis的SQL执行过程中有什么作用？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">核心组件</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`BoundSql`封装了即将执行的SQL语句和对应的参数。它负责将方法参数和SQL语句中的占位符进行绑定，并保存了SQL与参数之间的映射关系。</div>
          </div>
          <div class="card-source">来源: 4. BoundSql与参数绑定</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">当MyBatis执行完一条查询SQL后，哪个组件负责将返回的数据库结果集（ResultSet）转换成Java对象？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`ResultSetHandler`接口负责处理SQL查询结果。它会将数据库查询结果（`ResultSet`）根据`ResultMap`的定义映射为Java对象，支持POJO、List、Map等多种类型。</div>
          </div>
          <div class="card-source">来源: 5. ResultSetHandler与结果映射</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">`ResultMap`在MyBatis中起什么作用？它如何定义映射关系？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`ResultMap`定义了如何将数据库查询结果的列映射为Java对象的字段（属性）。它通过`<id>`和`<result>`等标签，将数据库中的列名（column）与Java对象的属性名（property）进行绑定。</div>
          </div>
          <div class="card-source">来源: 6. ResultMap与动态映射</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">流程</div>
          <div class="card-question">请简述MyBatis从调用`SqlSession`方法到返回结果的完整执行流程。</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">流程</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">1. 通过`SqlSession`调用方法，获取对应的`MappedStatement`。<br>2. 根据SQL和参数构建`BoundSql`对象，绑定参数。<br>3. 通过`Executor`执行SQL，将SQL和参数发送到数据库。<br>4. 数据库返回结果后，`ResultSetHandler`根据`ResultMap`将`ResultSet`映射为Java对象。<br>5. 返回映射后的Java对象给调用者。</div>
          </div>
          <div class="card-source">来源: 7. SQL执行与映射的执行流程</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">在`Executor`的`query`方法中，是如何利用`BoundSql`来执行一个预编译的SQL查询的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`Executor`会从`BoundSql`对象中获取SQL字符串（`boundSql.getSql()`）来创建JDBC的`PreparedStatement`，然后遍历`BoundSql`中的参数映射（`parameterMappings`）来为`PreparedStatement`设置参数。</div>
          </div>
          <div class="card-source">来源: 4. BoundSql与参数绑定</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">在`DefaultResultSetHandler`中，`mapRow()`方法的核心职责是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`mapRow()`方法的核心职责是根据`ResultMap`的配置，将`ResultSet`中的单行数据映射（转换）成一个Java对象实例。</div>
          </div>
          <div class="card-source">来源: 6. ResultMap与动态映射</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
